package test.gdata.maps;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import com.google.gdata.client.maps.MapQuery;
import com.google.gdata.client.maps.MapsService;
import com.google.gdata.data.maps.MapEntry;
import com.google.gdata.data.maps.MapFeed;
import com.google.gdata.util.AuthenticationException;
import com.google.gdata.util.ServiceException;

public class MapsClient {
	// The base URL for a user's calendar metafeed (needs a username appended).
	private static final String METAFEED_URL_BASE = "http://maps.google.com/maps/feeds/maps/";
	
	private MapsService service;
	
	private String username;
	
	private String authToken;
	
	public MapsClient(MapsService service, String username, String password){
		this.service = service;
		this.username = username;
		if(username != null && password != null){
			try {
				service.setUserCredentials(username, password);
			} catch (AuthenticationException e) {
				throw new IllegalArgumentException(
			            "Illegal username/password combination.");
			}	
		}
	}
	
	public void info(){
		System.out.println("Maps service: " + this.service.MAPS_SERVICE);
		System.out.println("Maps service version: " + this.service.MAPS_SERVICE_VERSION);
	}
	
//	public List<?> getFeeds() throws MalformedURLException{
//		final URL feedUrl = new URL("https://maps.google.com/maps/feeds/maps/default/full");
//		this.service.
//		return null;
//	}
	
	public List<MapEntry> getMaps() throws IOException, ServiceException{
		final URL feedUrl = new URL("https://maps.google.com/maps/feeds/maps/default/owned"); //new URL(METAFEED_URL_BASE + username + "/full");
	    MapFeed resultFeed = service.getFeed(feedUrl, MapFeed.class);
	    return resultFeed.getEntries();
	}
	
	public void uploadKML(String name, String filepath){
		
	}
}
